
<template>
  <div class="common_page act_wrap" v-loading="loading">
    <ul class="ul_wrap">
      <li
        v-for="(item, index) in tagList"
        :key="index"
        :class="{ active: current == index }"
        @click="handleCickTag(item, index)"
      >
        {{ item.name }}
      </li>
    </ul>
    <div class="temp_box">
      <div class="tempItem" v-for="(item, index) in tempList" :key="index">
        <img :src="item.screenshotLink" alt="" />
        <div class="tempTitle">{{ item.title }}</div>
        <div class="tips_wrap">
          <div class="creat" @click="handleCreate(item)">创建流程</div>
        </div>
      </div>
    </div>
    <el-dialog
      :visible.sync="centerDialogVisible"
      width="800px"
      center
      top='50vh'
      :close-on-click-modal="false"
      :modal-append-to-body="false"
      custom-class="Pub"
    >
      <div class="publish_box" ref="publish_box">
        <div class="box_l">
          <iframe id="iframe_wrap" :src="url"></iframe>
        </div>
        <div class="box_r">
          <div class="introduction_List">
            <div class="detail_t">功能描述</div>
            <div class="detail_d">
              {{ currentTemp.description }}
            </div>
            <div class="detail_t">使用场景</div>
            <div class="detail_d">
              {{ currentTemp.summary }}
            </div>
          </div>
          <div class="qr_box">
            <div class="btn_wrap">
              <div class="creat_btn" @click="createByTemp">创建流程</div>
            </div>
            <div class="qr_wrap">
              <qr-code :voteId="currentTemp.voteId" :size="120"></qr-code>
              <div class="tips_wrap">
                <span class="name">手机扫一扫查看效果</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import qrCode from "@/components/qrCode";
import { mapGetters } from "vuex";
export default {
  components: {
    qrCode,
  },
  data() {
    return {
      tagList: [],
      current: 0,
      centerDialogVisible: false,
      query: {
        pageNum: 1,
        pageSize: 10,
        title: "",
        voteCategoryId: "",
      },
      tempList: [],
      currentTemp: {},
      url: "",
    };
  },
  ...mapGetters("status", {
    loading: "loading",
  }),
  created() {
    this.getTemplateTag();
    this.getTemplate();
  },
  methods: {
    getTemplateTag() {
      this.$api("resource.getTemplateTag").then((res) => {
        console.log(res);
        this.tagList = res;
        this.tagList.unshift({ name: "全部", id: "" });
      });
    },
    getTemplate() {
      this.$api("resource.getTemplate", this.query).then((res) => {
        console.log(res);
        this.tempList = res.data;
      });
    },
    handleCickTag(item, index) {
      this.current = index;
      console.log(item);
      this.query.voteCategoryId = item.id;
      this.query.pageNum = 1;
      this.getTemplate();
    },
    handleCreate(item) {
      this.$api("vote.getqrcode", {
        id: item.voteId,
      }).then((res) => {
        this.url = res;
        this.centerDialogVisible = true;
      });
      this.currentTemp = item;
    },
    createByTemp() {
      this.$api("vote.copyVote", {
        id: this.currentTemp.voteId,
      }).then((res) => {
        this.centerDialogVisible = false;
        this.$message({
          message: "创建成功",
          type: "success",
          duration: 1000,
        });
        this.$router.push({
          path: "/manage/setup",
          query: {
            t: "act",
            id: res,
          },
        });
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.act_wrap {
  .ul_wrap {
    display: flex;
    li {
      font-size: 15px;
      margin: 0 10px;
      padding: 15px 0;
      cursor: pointer;
    }
    .active {
      color: $themeColor;
      border-bottom: 2px solid $themeColor;
    }
  }
  .temp_box {
    margin-top: 20px;
    display: flex;
    flex-wrap: wrap;
    .tempItem {
      width: 260px;
      margin: 10px 45px 34px 0;
      font-size: 0;
      position: relative;
      transition: all 0.5s;
      border-radius: 6px;
      &:hover {
        box-shadow: 0 20px 60px rgb(61 79 127 / 17%);
        transform: translateY(-10px);
      }

      img {
        width: 100%;
        height: 462px;
        border-radius: 6px 6px 0 0;
      }
      .tempTitle {
        font-size: 14px;
        text-align: center;
        border: 1px solid #f5f5f5;
        line-height: 26px;
      }
      .tips_wrap {
        position: absolute;
        border-radius: 6px;
        left: 0;
        top: 0;
        bottom: 0;
        right: 0;
        z-index: 6;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        background: rgba(0, 0, 0, 0);
        opacity: 0;
        cursor: pointer;
        &:hover {
          opacity: 1;
          background: rgba(0, 0, 0, 0.5);
          .creat {
            color: $themeColor;
            width: 110px;
            height: 35px;
            line-height: 35px;
            background-color: #3398ff;
            border-radius: 3px;
            font-size: 16px;
            letter-spacing: 1px;
            color: #fff;
            cursor: pointer;
            text-align: center;
          }
        }
      }
    }
  }
  ::v-deep.el-dialog__wrapper{
    overflow: hidden;
  }
  ::v-deep.Pub {
    transform: translateY(-50%);
    .el-dialog__header {
      padding: 0;
    }
    .el-dialog__body {
      padding: 0;
    }
  }
  .publish_box {
    display: flex;
    height: 600px;
    .box_l {
      flex: 0 0 375px;
      #iframe_wrap {
        width: 100%;
        height: 100%;
      }
    }
    .box_r {
      flex: 1;
      padding: 0 20px;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      .introduction_List {
        width: 100%;
        .detail_t {
          font-size: 14px;
          margin: 10px 0 5px;
        }
        .detail_d {
          font-size: 12px;
          color: #999;
        }
      }
      .qr_box {
        width: 100%;
        display: flex;
        margin-top: 10px;
        .btn_wrap {
          flex: 1;
          display: flex;
          align-items: flex-end;
          .creat_btn {
            width: 200px;
            height: 33px;
            line-height: 33px;
            text-align: center;
            color: #fff;
            background: $themeColor;
            cursor: pointer;
          }
        }

        .qr_wrap {
          width: 120px;
          height: 120px;
          .tips_wrap {
            text-align: center;
            span {
              font-size: 12px;
              color: #606266;
              margin-top: 10px;
            }
          }
        }
      }
    }
  }
}
</style>